home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / std_unix / archive / text0097.txt < prev    next >
Encoding:
Text File  |  1993-07-06  |  1.3 KB  |  44 lines

  1. Submitted-by: gwc@root.co.uk (Geoff Clare)
  2.  
  3. In <212aaeINNl49@rodan.UU.NET> ddm26@cas.org (De Mickey) writes:
  4. >However, the function return value can look valid (e.g.
  5. >zero), so the application must set errno to zero before the
  6. >call, and then test errno afterwards, if it wants to be sure
  7. >the conversion was successful.
  8.  
  9. >    errno = 0;
  10. >    dbl = strtod(ptr, &endptr);
  11. >    if (errno != 0) {
  12. >       /* complain to someone */
  13. >    }
  14.  
  15. Although this example is probably safe, in general you should only ever
  16. examine errno if the function return value indicates that it safe to
  17. do so.  This is because POSIX allows functions to set errno to a non-zero
  18. value when they succeed (the classic example is errno being set to ENOTTY
  19. by stdio functions).
  20.  
  21. So in the case of pathconf(), which started this thread, instead of
  22.  
  23.     errno = 0;
  24.     longval = pathconf(file, _PC_WHATEVER);
  25.     if (errno != 0) {
  26.        /* complain to someone */
  27.     }
  28.  
  29. you should use
  30.  
  31.     errno = 0;
  32.     longval = pathconf(file, _PC_WHATEVER);
  33.     if (longval == -1 && errno != 0) {
  34.        /* complain to someone */
  35.     }
  36.  
  37. -- 
  38. Geoff Clare <gwc@root.co.uk> (USA antiquated mailers: ...!uunet!root.co.uk!gwc)
  39. UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273
  40.  
  41.  
  42. Volume-Number: Volume 31, Number 100
  43.  
  44.